package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         1,
		Discription: "两数之和",
		Level:       1,
		Labels: map[string]int{
			"哈希表": 1,
		},
	})
}

func TwoSum(nums []int, target int) []int {
	//遍历一次就够
	indexMap := make(map[int]int, len(nums))
	for index, val := range nums {
		index2, exist := indexMap[target-val]
		if exist {
			return []int{index, index2}
		}
		indexMap[val] = index
	}

	return []int{}
}
